<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.mselect.js?"></script>
<script type="text/javascript">
$(function(){
	var shipping_method_data = <?=$shipping_method_data?>;
	$(document).mselect(shipping_method_data, 'shipping_method_id', 'shipping_method_id', "<?=$sales_order['shipping_method']?>", 'shipping_method_id');
	var i = 1;
	var attr_count =1;
	$("#add_product").click(function(){
		var _html = "<tr>";
		_html += "<td><input type='checkbox' name='gift_flag_add" + i + "' value='<?=Q::ini('custom_flag/sales_order_item_gift_flag/gift/value')?>' /></td>";
		_html += "<td><input type='text' size='7' name='product_number_add" + i + "' class='ajax_product' /></td>";
		_html += "<td><input type='text' size='7' name='sales_price_add" + i + "' value='' /></td>";
		_html += "<td><input type='text' size='7' name='quantity_add" + i + "' value='' /></td>";
		_html += "<td><input type='text' name='shop_item_id_add" + i + "' value='' />";
		_html += "<td><input type='text' name='shop_transaction_id_add" + i + "' value='' />";
		_html += "<td><a href='javascript:void(0);' class='add_attr' rel='order_item_add"+ i +"'>添加属性</a> <a href='javascript:void(0);' class='del_product'>删除产品</a></td>";
		_html += "</tr>";
		$(".list_table").append(_html);
		i++;
	});
	$(".add_attr").live("click", function(){
		var unid = $(this).attr("rel");
		var _html = "<tr>";
		_html += "<td><input type='text' name='"+unid+"_attr_add"+attr_count+"_name' value='' /></td>";
		_html += "<td><input type='text' name='"+unid+"_attr_add"+attr_count+"_value' value='' /></td>";
		_html += "<td><select name='"+unid+"_attr_add"+attr_count+"_prefix'><option value='+'>+</option><option value='-'>-</option></select></td>";
		_html += "<td><input type='text' size='7' name='"+unid+"_attr_add"+attr_count+"_price' value='' /></td>";
		_html += "<td><a href='javascript:void(0);' class='del_attr'>删除属性</a></td></tr>";
		attr_count++;
		if ($(this).parent().parent().next().is(".attr"))
		{
			$(this).parent().parent().next().find("table").append(_html);
		}
		else
		{
			_html = "<tr class='attr'><td colspan='7'><table width='100%' ><tr><td>属性名称</td><td>属性值</td><td width='100'>属性价格前缀</td><td width='70'>属性价格</td><td>属性操作</td></tr>" + _html + "</table>";
			$(this).parent().parent().after(_html);
		}
	});
	$(".del_product").live("click", function(){
		if ( ! confirm("确定删除该产品？"))
		{
			return false;
		}
		else
		{
			if($(this).parent().parent().next().is(".attr"))
			{
				$(this).parent().parent().next().remove();
			}
			$(this).parent().parent().remove();
		}
	});
	$(".del_attr").live("click", function(){
		if ( ! confirm("确定删除该属性？"))
		{
			return false;
		}
		else
		{
			$(this).parent().parent().remove();
		}
	});
})
</script>
<h2>修改销售订单信息</h2>
<form action="<?=url('Sales::Order/ProductInfoEditSave')?>" method="post">
<table width="50%" class="form_table">
	<tr>
		<th>本地单号</th>
		<td><?=$sales_order['number']?></td>
		<th>网站单号</th>
		<td><?=$sales_order['shop_order_number']?></td>
	</tr>
	<tr>
		<th>网站/店铺</th>
		<td><?=$sales_order['shop_name']?></td>
		<th>支付方式</th>
		<td><?=Helper_BSS_Normal::getIniOne('sales_order_payment_method', 'value', $sales_order['payment_method'], 'name')?></td>
	</tr>
	<tr>
		<th>邮寄方式</th>
		<td><?=$sales_order['shipping_method_name']?></td>
		<th>发货类型</th>
		<td>
			<?=Helper_BSS_Normal::getIniOne('sales_order_send_method', 'value', $sales_order['send_method'], 'name')?>
			<?if ($sales_order['send_method'] == Q::ini('custom_flag/sales_order_send_method/resend/value')):?>
			<?='('.Helper_BSS_Normal::getIniOne('sales_order_resend_reason', 'value', $sales_order['resend_reason'], 'name').')'?>
			<?endif;?>
		</td>
	</tr>
	<tr>
		<th>交易号</th>
		<td><?=$sales_order['transaction_id']?></td>
		<th>买家全名</th>
		<td><?=$customer['fullname']?></td>
	</tr>
	<tr>
		<th>买家电话</th>
		<td><?=$customer['phone']?></td>
		<th>买家Email</th>
		<td><?=$customer['email']?></td>
	</tr>
	<tr>
		<th>地址</th>
		<td><?=$customer['street1']?></td>
		<th>城市</th>
		<td><?=$customer['city']?></td>
	</tr>
	<tr>
		<th>州/省</th>
		<td><?=$customer['state']?></td>
		<th>国家(en)</th>
		<td><?=$customer['country']?></td>
	</tr>
	<tr>
		<th>国家(cn)</th>
		<td><?=$customer['country_cn']?></td>
		<th>邮编</th>
		<td><?=$customer['zip']?></td>
	</tr>
	<tr>
		<th>运费</th>
		<td><?=$sales_order['shipping_fee']?></td>
		<th>折扣</th>
		<td><?=$sales_order['discount']?></td>
	</tr>
	<tr>
		<th>仓库/邮寄</th>
		<td colspan="3"><input type="hidden" name="shipping_method_id" id="shipping_method_id" value="" /></td>
	</tr>
</table>
<table width="70%" class="list_table">
<tr>
	<th>赠品</th>
	<th>产品编号</th>
	<th>单价</th>
	<th>数量</th>
	<th>ShopItemId</th>
	<th>ShopTransactionId</th>
	<th width="120">操作</th>
</tr>
<?foreach ($sales_order['item'] as $i):?>
<tr>
	<td><input type="checkbox" name="gift_flag_<?=$i['id']?>" value="<?=Q::ini('custom_flag/sales_order_item_gift_flag/gift/value')?>" <?if ($i['gift_flag'])echo "checked='checked'"?>/></td>
	<td><input type="text" size="7" name="product_number_<?=$i['id']?>" class="ajax_product" value="<?=$i['number']?>" /></td>
	<td><input type="text" size="7" name="sales_price_<?=$i['id']?>" value="<?=$i['sales_price']?>" /></td>
	<td><input type="text" size="7" name="quantity_<?=$i['id']?>" value="<?=$i['quantity']?>" /></td>
	<td><input type="text" name="shop_item_id_<?=$i['id']?>" value="<?=$i['shop_item_id']?>" /></td>
	<td><input type="text" name="shop_transaction_id_<?=$i['id']?>" value="<?=$i['shop_transaction_id']?>" /></td>
	<td>
		<a href="javascript:void(0);" class="add_attr" rel="order_item_<?=$i['id']?>">添加属性</a>
		<a href="javascript:void(0);" class="del_product">删除产品</a>
	</td>
</tr>
<?if ($i['attr']):?>
<tr class="attr">
	<td colspan="7">
	<table width="100%">
		<tr>
			<td>属性名称</td>
			<td>属性值</td>
			<td width="100">属性价格前缀</td>
			<td width="70">属性价格</td>
			<td>属性操作</td>
		</tr>
		<?foreach ($i['attr'] as $ia):?>
		<tr>
			<td><input type="text" name="order_item_<?=$i['id']?>_attr_<?=$ia['id']?>_name" value="<?=$ia['name']?>" /></td>
			<td><input type="text" name="order_item_<?=$i['id']?>_attr_<?=$ia['id']?>_value" value="<?=$ia['value']?>" /></td>
			<td>
				<select name="order_item_<?=$i['id']?>_attr_<?=$ia['id']?>_prefix">
					<option value="+" <?if ($ia['prefix']=='+')echo "selected='selected'"?>>+</option>
					<option value="-" <?if ($ia['prefix']=='-')echo "selected='selected'"?>>-</option>
				</select>
			</td>
			<td><input type="text" size="7" name="order_item_<?=$i['id']?>_attr_<?=$ia['id']?>_price" value="<?=sprintf('%.2f', $ia['price'])?>" /></td>
			<td><a href="javascript:void(0);" class="del_attr">删除属性</a></td>
		</tr>
		<?endforeach;?>
	</table>
	</td>
</tr>
<?endif;?>
<?endforeach;?>
</table>
<a id="add_product">添加该订单产品</a>
<input type="hidden" name="sales_order_id" value="<?=$sales_order['id']?>"/>
<input type="hidden" name="history" value="<?=isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : url('Sales::Order/List')?>" />
<div align="center"><input type="submit" class="button" value="保存" /><input type="hidden" name="<?=Q::ini('unique_token_name');?>" value="<?=Helper_BSS_Normal::genToken();?>"/></div>
</form>
<?php $this->_endblock();?>